package com.bolt.report.engine.fill;

import com.bolt.common.utils.StrUtil;
import com.bolt.report.engine.FillElementVisitor;
import com.bolt.report.engine.export.Exporter;
import com.bolt.report.engine.model.Expression;

import java.nio.charset.Charset;

public class FillTextElement extends BaseFillElement<String> {


    public FillTextElement(FillContext fillContext,Expression expr,Object value) {
        this.fillContext = fillContext;
        this.expr = expr;
        setValue(StrUtil.str(value, Charset.defaultCharset()));
     }


    public FillTextElement(Object value,FillContext fillContext) {
        setValue(StrUtil.str(value, Charset.defaultCharset()));
        this.fillContext = fillContext;
    }


    @Override
    public String getValue() {
        if (StrUtil.isBlank(this.value)) {
            this.value = StrUtil.EMPTY;
        }
        return value;
    }


    @Override
    public <T> void accept(FillElementVisitor<T> visitor, T arg) {
        visitor.visit(this, arg);
    }

    @Override
    public <E extends Exporter> void accept(ExporterVisitor<E> visitor, E exporter)  {
        visitor.visit(this,exporter);
    }
}